/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Admin.DAO;

import Admin.Model.Cash;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author home
 */
public class CashDAO {
// not use
    private Connection myCon;
    private PreparedStatement ps;
    private ResultSet rs;
    private String strCommand = "";

    public ArrayList<Cash> GetAll() {
        ArrayList<Cash> listCash = new ArrayList<Cash>();
        Cash cash = null;
        try {

            strCommand = "select * from tbl_Cash";
            myCon = myConnection.getConnection();
            myConnection.getConnection();
            ps = myCon.prepareStatement(strCommand);

            rs = ps.executeQuery();
            while (rs.next()) {
                  cash=new Cash();
                  cash.setCashID(rs.getInt("cashID"));
                  cash.setCashPIN(rs.getString("cashPIN"));
                  cash.setCashSeries(rs.getString("cashSeries"));
                  cash.setCashStatus(rs.getInt("cashStatus"));
                  listCash.add(cash);

            }
            return listCash;
        } catch (SQLException ex) {
            Logger.getLogger(Cash.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            myConnection.closeConnection(myCon, ps, rs);
        }
        return null;
    }

     public Cash GetBySeries(String cashSeries) {

        Cash cash=new Cash();
        try {

            strCommand = "select * from tbl_Cash WHERE cashSeries=?";

            myCon = myConnection.getConnection();
            ps = myCon.prepareStatement(strCommand);
            ps.setString(1, cashSeries);
            rs = ps.executeQuery();
            while (rs.next()) {
               cash.setCashID(rs.getInt("cashID"));
               cash.setCashPIN(rs.getString("cashPIN"));
               cash.setCashSeries(rs.getString("cashSeries"));
               cash.setCashStatus(rs.getInt("cashStatus"));
            }
            return cash;
        } catch (SQLException ex) {
            Logger.getLogger(Cash.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            myConnection.closeConnection(myCon, ps, rs);
        }
        return cash;
    }
      public boolean changeStatus(int cashID, int cashStatus) {
        boolean flag = false;
        try {
            strCommand = "UPDATE tbl_Cash SET cashStatus = ? WHERE cashID = ?";
            myCon = myConnection.getConnection();
            ps = myCon.prepareStatement(strCommand, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
            ps.setInt(1, cashStatus);
            ps.setInt(2, cashID);
            int i = ps.executeUpdate();
            if (i > 0) {
                flag = true;
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        } finally {
            myConnection.closeConnection(myCon, ps, null);
        }
        return flag;
    }
}
